package com.aust.furniture.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.aust.furniture.entity.Customer;
import com.aust.furniture.mapper.CustomerMapper;
import com.aust.furniture.service.ICustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 顾客service实现类
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    /**
     * 分页查询顾客数据
     *
     * @param pageNum  第几页
     * @param pageSize 每页多少条数据
     * @param param    查询参数-顾客名称
     * @return
     */
    @Override
    public IPage<Customer> selectCustomerPage(int pageNum, int pageSize, String param) {
        QueryWrapper<Customer> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotEmpty(param)){
            queryWrapper.like("name",param);
        }
        Page<Customer> page = new Page<>(pageNum,pageSize);
        return customerMapper.selectPage(page,queryWrapper);
    }

    /**
     * 新增一条顾客信息
     *
     * @param customer
     */
    @Override
    public int addCustomer(Customer customer) {
        return customerMapper.insert(customer);
    }

    /**
     * 修改一条顾客信息
     *
     * @param customer
     */
    @Override
    public int editCustomer(Customer customer) {
        return customerMapper.updateById(customer);
    }

    /**
     * 根据主键id查询一个顾客对象
     *
     * @param id
     * @return
     */
    @Override
    public Customer queryCustomerById(Integer id) {
        return customerMapper.selectById(id);
    }

    /**
     * 根据主键id删除一个顾客对象
     *
     * @param id
     * @return
     */
    @Override
    public int delCustomerById(Integer id) {
        return customerMapper.deleteById(id);
    }

}
